package com.kingdee.pda.ui.out_check;

import android.content.Context;

import com.example.basecommon.http.MyObserver;
import com.example.basecommon.http.RxHelper;
import com.example.basecommon.http.rxjava.BaseResponse;
import com.example.basecommon.http.rxjava.HttpUtils;
import com.example.basecommon.utils.ConstantUtil;
import com.kingdee.pda.Api;
import com.kingdee.pda.entity.OutCheckRequestBean;
import com.kingdee.pda.entity.ScanOutOrderInfoBean;
import com.kingdee.pda.entity.ScanSnResponsebean;

import java.util.HashMap;

/**
 * @author：dlj
 * @data：2021/9/22:10:31
 * @des：出库复核Presenter
 */
public class OutCheckPresenter implements OutCheckContract.IOutCheckPresenter {
    private Context context;
    private OutCheckContract.IOutCheckView view;

    public OutCheckPresenter(Context context, OutCheckContract.IOutCheckView view) {
        this.context = context;
        this.view = view;
    }

    @Override
    public void reviewStockOutBillOrExpressNo(String scanbillno) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("scanbillno", scanbillno);
        map.put("review", true);

        MyObserver<ScanOutOrderInfoBean> myObserver = new MyObserver<ScanOutOrderInfoBean>(context) {
            @Override
            public void onSuccess(BaseResponse<ScanOutOrderInfoBean> result) {
                view.reviewStockOutBillOrExpressNoSuccess(result.data);
            }

            @Override
            public void onFailure(BaseResponse result, String msg) {
                view.reviewStockOutBillOrExpressNoFailed(result.message);
            }
        };
        HttpUtils.request(Api.class)
                .scanStockOutBillOrExpressNo(ConstantUtil.SCANORDERNO, map)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(myObserver);
    }

    @Override
    public void pdaSnScan(String sn) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("SN", sn);
//        map.put("snStatus", "in_library");

        MyObserver<ScanSnResponsebean> myObserver = new MyObserver<ScanSnResponsebean>(context, false) {
            @Override
            public void onSuccess(BaseResponse<ScanSnResponsebean> result) {
                view.pdaSnScanSuccess(result.data);
            }

            @Override
            public void onFailure(BaseResponse result, String msg) {
                view.pdaSnScanFailed(result.message);
            }
        };
        HttpUtils.request(Api.class)
                .pdaScanSn(ConstantUtil.PDASNSCAN, map)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(myObserver);
    }

    @Override
    public void pdaCollectNullSn(String sn) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("SN", sn);
        map.put("snStatus", "in_library");

        MyObserver<ScanSnResponsebean> myObserver = new MyObserver<ScanSnResponsebean>(context, false) {
            @Override
            public void onSuccess(BaseResponse<ScanSnResponsebean> result) {
                view.pdaCollectNullSnSuccess(result.data);
            }

            @Override
            public void onFailure(BaseResponse result, String msg) {
                view.pdaCollectNullSnFailed(result.message);
            }
        };
        HttpUtils.request(Api.class)
            .pdaScanSn(ConstantUtil.PDACOLLECTNULLSN, map)
            .compose(RxHelper.observableIO2Main(context))
            .subscribe(myObserver);
    }

    @Override
    public void confirmStockOutReview(OutCheckRequestBean outCheckRequestBean) {
        outCheckRequestBean.setType("2");
        MyObserver myObserver = new MyObserver(context) {
            @Override
            public void onSuccess(BaseResponse result) {
                view.confirmStockOutReviewResult(true, result.message);
            }

            @Override
            public void onFailure(BaseResponse result, String msg) {
                view.confirmStockOutReviewResult(false, result.message);
            }
        };
        HttpUtils.request(Api.class)
                .confirmStockOutReview(ConstantUtil.CONFRMSTOCKOUTREVIEW, outCheckRequestBean)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(myObserver);
    }
}
